package com.jsnj33.pdaproject.adapter;


import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jsnj33.pdaproject.R;
import com.jsnj33.pdaproject.bean.PayingBillsBean;
import com.jsnj33.pdaproject.bean.SetOfBookBean;

import java.util.List;

/**
 * @author 33oa
 * @date 2018/11/29
 */
public abstract class PersonnelAdapter extends RecyclerView.Adapter<PersonnelAdapter.ViewHolder> {

    private Context mContext;
    private List<SetOfBookBean> list;

    public PersonnelAdapter(Context context) {
        this.mContext = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_personnel, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        holder.tv.setText(list.get(position).getNAME());
    }

    @Override
    public int getItemCount() {
        return list != null ? list.size() : 0;
    }


    public void setList(List<SetOfBookBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        TextView tv;
        ViewHolder(View itemView) {
            super(itemView);

            tv = itemView.findViewById(R.id.tv);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    clickItem(list.get(getAdapterPosition()));
                }
            });
        }
    }

    protected abstract void clickItem(SetOfBookBean setOfBookBean);
}
